import * as types from "../../mutation-types";
import lazyLoading from "./lazyLoading";
// show: meta.label -> name
// name: component name
// meta.label: display label

const state = {
  items: [
    {
      path: "/about",
      meta: {
        auth: false,
        icon: "fa-tachometer",
        show: false,
        label: "about"
      },
      component: lazyLoading("about/Default")
    },
    {
      path: "/",
      meta: {
        auth: false,
        icon: "fa-tachometer",
        show: false,
        label: "Home"
      },
      component: lazyLoading("home/Default"),
      children: [
        {
          name: "Map",
          path: "",
          component: lazyLoading("home/Map"),
          meta: {
            link: "home/Map.vue",
            show: false
          }
        },
        {
          name: "Map",
          path: "map",
          component: lazyLoading("home/Map"),
          meta: {
            link: "home/Map.vue",
            show: false
          }
        },
        {
          name: "Status",
          path: "status",
          component: lazyLoading("home/Status"),
          meta: {
            link: "home/Status.vue",
            show: false
          }
        }
      ]
    },
    {
      path: "/search",
      component: lazyLoading("search/Default"),
      meta: {
        auth: false,
        icon: "fa-tachometer",
        show: false,
        label: "Search"
      }
    },
    {
      path: "/notification",
      component: lazyLoading("notification/Default"),
      meta: {
        auth: false,
        icon: "fa-tachometer",
        show: false,
        label: "Notification"
      }
    },
    {
      path: "/about",
      component: lazyLoading("about/Default"),
      meta: {
        auth: false,
        icon: "fa-tachometer",
        show: false,
        label: "About"
      }
    },
    {
      path: "/personal",
      meta: {
        auth: false,
        icon: "fa-tachometer",
        show: false,
        label: "Personal"
      },
      component: lazyLoading("personal/Default"),
      children: [
        {
          name: "Follow",
          path: "",
          component: lazyLoading("personal/CardList"),
          meta: {
            link: "personal/Follow.vue",
            show: false
          }
        },
        {
          name: "Follow",
          path: "follow",
          component: lazyLoading("personal/CardList"),
          meta: {
            link: "personal/Follow.vue",
            show: false
          }
        },
        {
          name: "Receive",
          path: "receive",
          component: lazyLoading("personal/CardList"),
          meta: {
            link: "personal/Receive.vue",
            show: false
          }
        }
      ]
    }
  ]
};

const mutations = {
  [types.EXPAND_MENU](state, menuItem) {
    if (menuItem.index > -1) {
      if (state.items[menuItem.index] && state.items[menuItem.index].meta) {
        state.items[menuItem.index].meta.expanded = menuItem.expanded;
      }
    } else if (menuItem.item && "expanded" in menuItem.item.meta) {
      menuItem.item.meta.expanded = menuItem.expanded;
    }
  }
};

export default {
  state,
  mutations
};
